using System;

namespace ActivUFRJ.Classes.Geral
{
    public class DBLingua : Connection.MySQL
    {
        public DBLingua() : base(ref Connection.DBConnection.myConnection)
        {

        }

        private void FillLingua(Lingua lingua)
        {
            lingua.ID = Convert.ToInt32(this.TableGetValue("LNG_ID"));
            lingua.Descricao = Convert.ToString(this.TableGetValue("LNG_Descricao"));
            lingua.Sigla = Convert.ToString(this.TableGetValue("LNG_SIGLA"));
        }

        internal Lingua[] GetListaLingua()
        {
            try
            {
                string SQL = "SELECT * from LINGUAS";

                this.SetSQL(SQL);

                int i = 0;
                Lingua[] listaLinguas = new Lingua[this.GetRowCount()];

                while (i < this.GetRowCount())
                {
                    Lingua novaLingua = new Lingua();
                    this.FillLingua(novaLingua);
                    listaLinguas[i] = novaLingua;

                    i++;
                    this.TableMoveNext();
                }

                return listaLinguas;
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        internal bool CarregarLingua(Lingua lingua)
        {
            try
            {
                string SQL = "SELECT * from linguas where LNG_ID = " + lingua.ID.ToString();

                this.SetSQL(SQL);
                if (!this.IsTableOver())
                {
                    FillLingua(lingua);
                    return true;
                }
                else return false;
            }
            catch (Exception ex)
            {
                return false;
            }
        }

        internal bool CarregarLinguaUsuario(Usuario.LinguaUsuario linguaUsuario)
        {
            try
            {
                string SQL = "SELECT * from linguas where LNG_ID = " + linguaUsuario.ID.ToString();

                this.SetSQL(SQL);
                if (!this.IsTableOver())
                {
                    FillLingua(linguaUsuario);
                    return true;
                }
                else return false;
            }
            catch (Exception ex)
            {
                return false;
            }
        }

    }
}
